<?php
/*
* PHPSDL - Testing sample for SMPEG support
*
* Note: that's a quick hack and doesn't expos the full functionality of the SMPEG API.
*
* Markus Fischer <mfischer@guru.josefine.at>
*
*/

set_time_limit(0);
dl("php_sdl.dll");

//if(!extension_loaded('sdl_smpeg')) {
//	fprintf(STDERR, 'The extension sdl_smpeg must be installed to run this script.' . PHP_EOL);
//	exit(1);
//}

error_reporting(E_ALL);
//sdl_expose_internal_errors(true);
if (!isset($argv)) $argv = $_SERVER['argv'];

if (!($smpeg = SMPEG_New($argv[1], $info, 0)))
	exit;
if ($info->width == 0 || $info->height == 0)
	exit;
SMPEG_enableaudio($smpeg, false);
	
if (!SDL_Init(SDL_INIT_VIDEO))
	exit;

if (!($screen = SDL_SetVideoMode($info->width, $info->height, 0, 0)))
	exit;
	
SMPEG_setdisplay($smpeg, $screen, NULL, NULL);

SMPEG_play($smpeg);

echo "up - pause/play\ndown - stop\nright - play\nleft - rewind\n\n";

$done = false;
while (!$done) {
	if (SDL_WaitEvent(&$event)) {
		switch ($event['type']) {
			case SDL_KEYDOWN:
				switch ($event['key']['keysym']['sym']) {
					case SDLK_UP:
						SMPEG_pause($smpeg);
						break;
					case SDLK_LEFT:
						SMPEG_rewind($smpeg);
						break;
					case SDLK_RIGHT:
						SMPEG_play($smpeg);
						break;
					case SDLK_DOWN:
						SMPEG_stop($smpeg);
						break;
				}
				if ($event['key']['keysym']['sym'] != SDLK_ESCAPE)
					break;
			case SDL_QUIT:
				$done = true;
				break;
		}
	}
}

?>
